#ifndef STORAGE_H
#define STORAGE_H

#include <QString>
#include <QMap>
#include <QVector>
#include <QSet>

#include "utils.h"

class Storage
{
public:
    Storage();
    ~Storage();

    class FileIndex * AddFile(const QString & name);
    class FileIndex * GetFile(const QString & name) const;
    const QMap<QString, FileIndex *> & GetFileIndexs() const { return m_dictFileIndex; }
    void RemoveFile(const QString & name);

    void RegLine(class FileIndex * fileIndex, const QString & text, qint64 posStart, qint64 posEnd);
    long int GetLineCount() const;
    // long int GetInvalidLineCount() const { return m_invalidLineCount; }
    void Rebuild();

    const QSet<QString> &  GetLevels() const { return m_levels; }
    const QSet<QString> &  GetTimes() const { return m_times; }
    const QSet<QString> &  GetThreadIds() const { return m_threadIds; }
    const QSet<QString> &  GetCate1s() const { return m_cate1s; }
    const QSet<QString> &  GetCate2s() const { return m_cate2s; }
    const QSet<QString> &  GetCate3s() const { return m_cate3s; }

    static const auto ITEM_COUNT = 7;
    static bool ParseLine(QStringRef items[ITEM_COUNT], QStringRef & desc, const QString & text);

    void Search(const QString & filename, const QString & level, const QString & time, const QString & threadId, const QString & cate1, const QString & cate2, const QString & cate3, QSet<Line> & result);

private:
    QMap<QString, FileIndex *> m_dictFileIndex;
    // long int m_lineCount;
    // long int m_invalidLineCount;
    QSet<QString> m_levels;
    QSet<QString> m_times;
    QSet<QString> m_threadIds;
    QSet<QString> m_cate1s;
    QSet<QString> m_cate2s;
    QSet<QString> m_cate3s;
};

#endif // STORAGE_H
